package com.itheima.mapper;

import com.itheima.pojo.Clazz;
import com.itheima.pojo.ClazzQueryParam;
import com.itheima.pojo.Student;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ClazzMapper {


    /**
     * 分页查询班级信息
     * @return
     */
    List<Clazz> list(ClazzQueryParam clazzQueryParam);


    /**
     * 查询所有班级信息
     * @return
     */
    List<Clazz> getInfo();


    /**
     * 根据Id删除班级
     * @param id
     */
    void deleteById(Integer id);


    /**
     * 新增班级
     * @param clazz
     */
    @Insert("insert into clazz (name, room, begin_date, end_date, master_id, subject ,create_time ,update_time)" +
            "values (#{name}, #{room},#{beginDate}, #{endDate}, #{masterId}, #{subject},#{createTime},#{updateTime})" )
    void insert(Clazz clazz);


    /**
     * 修改员工信息
     * @param clazz
     */
    void update(Clazz clazz);


    /**
     * 根据Id回显数据
     * @param id
     * @return
     */
    @Select("select * from clazz where id = #{id}")
    Clazz getInfoById(Integer id);


    /**
     * 根据ID得到班级名称
     * @param id
     * @return
     */
    @Select("select name from clazz where id = #{id}")
    String getClazzNameById(Integer id);


    /**
     * 查找该班级有无学生
     * @param id
     * @return
     */
    @Select("select s.* from student s left join clazz c on s.clazz_id = c.id where c.id = #{id}")
    List<Student> getStudentById(Integer id);


}
